/***************************************************************************

-------------------
    begin                : 
    copyright            : kuzkok
    email                : kuzkok at gmail.com

***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*   
*   Данная программа является свободным программным обеспечением;         *
*   Вы можете распространять ее и/или модифицировать в соответствии с     *
*   GNU General Public License опубликованной Фондом свободного           *
*   программного обеспечения; используемая версия лицензии - 2 или        *
*   (по вашему выбору) любая более поздняя                                *
***************************************************************************/

#include "stationseries.h"

StationSeries::StationSeries() :
    CenterlinePolyline("stationseries")
{
}

StationSeries::StationSeries(QUuid theEventID) :
        CenterlinePolyline(theEventID, "stationseries")
{
    if(mObjectState)
    {
        mSeriesName = mSelectQuery->value(mSelectQuery->record().indexOf("seriesname")).toString();
        mSeriesOrder = mSelectQuery->value(mSelectQuery->record().indexOf("seriesorder")).toInt();
        mSubTypeCD = mSelectQuery->value(mSelectQuery->record().indexOf("subtypecd")).toInt();
        mBeginStation = mSelectQuery->value(mSelectQuery->record().indexOf("beginstation")).toDouble();
        mEndStation = mSelectQuery->value(mSelectQuery->record().indexOf("endstation")).toDouble();
        mFromConnectionStationValue = mSelectQuery->value(mSelectQuery->record().indexOf("fromconnectionstationvalue")).toDouble();
        mToConnectionStationValue = mSelectQuery->value(mSelectQuery->record().indexOf("toconnectionstationvalue")).toDouble();
        mFromSeriesEventID = QUuid(mSelectQuery->value(mSelectQuery->record().indexOf("fromserieseventid")).toString());
        mToSeriesEventID = QUuid(mSelectQuery->value(mSelectQuery->record().indexOf("toserieseventid")).toString());
        mLineLoopEventID = QUuid(mSelectQuery->value(mSelectQuery->record().indexOf("lineloopeventid")).toString());

    }
}

void StationSeries::buildInsertStatement()
{
    CenterlinePolyline::buildInsertStatement();
    mInsertStatementFields += ", seriesname"
                             ", seriesorder"
                             ", subtypecd"
                             ", beginstation"
                             ", endstation"
                             ", fromconnectionstationvalue"
                             ", toconnectionstationvalue"
                             ", fromserieseventid"
                             ", toserieseventid"
                             ", lineloopeventid";
    mInsertStatementValues += ", :seriesname"
                             ", :seriesorder"
                             ", :subtypecd"
                             ", :beginstation"
                             ", :endstation"
                             ", :fromconnectionstationvalue"
                             ", :toconnectionstationvalue"
                             ", :fromserieseventid"
                             ", :toserieseventid"
                             ", :lineloopeventid";
}

void StationSeries::buildUpdateStatement()
{
    CenterlinePolyline::buildUpdateStatement();
    mUpdateStatement += ",seriesname = :seriesname"
                       ",seriesorder = :seriesorder"
                       ",subtypecd = :subtypecd"
                       ",beginstation = :beginstation"
                       ",endstation = :endstation"
                       ",fromconnectionstationvalue = :fromconnectionstationvalue"
                       ",toconnectionstationvalue = :toconnectionstationvalue"
                       ",fromserieseventid = :fromserieseventid"
                       ",toserieseventid = :toserieseventid"
                       ",lineloopeventid = :lineloopeventid";
}

void StationSeries::bindQueryValues(QSqlQuery &query)
{
    CenterlinePolyline::bindQueryValues(query);
    query.bindValue(":seriesname", mSeriesName);
    query.bindValue(":seriesorder", mSeriesOrder);
    query.bindValue(":subtypecd", mSubTypeCD);
    query.bindValue(":beginstation", mBeginStation);
    query.bindValue("endstation", mEndStation);
    query.bindValue(":fromconnectionstationvalue", mFromConnectionStationValue);
    query.bindValue(":toconnectionstationvalue", mToConnectionStationValue);
    query.bindValue(":fromserieseventid", UuidToVariant(mFromSeriesEventID));
    query.bindValue(":toserieseventid", UuidToVariant(mToSeriesEventID));
    query.bindValue(":lineloopeventid", UuidToVariant(mLineLoopEventID));

}

